<template>
  <div class="general-settings">
    <!-- 头部栏 -->
    <HeaderComponent 
      :isLoggedIn="isLoggedIn"
      :userInfo="userInfo"
      :showUserPanel="showUserPanel"
      @open-login="$emit('open-login')"
      @toggle-user-panel="$emit('toggle-user-panel')"
      @logout="$emit('logout')"
    />
    
    <!-- 主布局 -->
    <div class="main-layout">
      <!-- 左侧设置导航栏 -->
      <aside class="settings-sidebar">
        <div class="sidebar-header">
          <h3>设置</h3>
        </div>
        <ul class="settings-nav">
          <li class="nav-item">
            <router-link to="/user/settings/profile" class="nav-link">
              <span class="nav-icon">👤</span>
              <span>个人资料</span>
            </router-link>
          </li>
          <li class="nav-item">
            <router-link to="/user/settings/account" class="nav-link">
              <span class="nav-icon">🔐</span>
              <span>账号设置</span>
            </router-link>
          </li>
          <li class="nav-item active">
            <router-link to="/user/settings/general" class="nav-link">
              <span class="nav-icon">⚙️</span>
              <span>通用设置</span>
            </router-link>
          </li>
          <li class="nav-item">
            <router-link to="/user/settings/notifications" class="nav-link">
              <span class="nav-icon">🔔</span>
              <span>消息设置</span>
            </router-link>
          </li>
          <li class="nav-item">
            <router-link to="/user/settings/block" class="nav-link">
              <span class="nav-icon">🚫</span>
              <span>屏蔽管理</span>
            </router-link>
          </li>
          <li class="nav-item">
            <router-link to="/user/settings/tags" class="nav-link">
              <span class="nav-icon">🏷️</span>
              <span>标签管理</span>
            </router-link>
          </li>
        </ul>
      </aside>
      
      <!-- 右侧内容区 -->
      <main class="settings-content">
        <div class="settings-header">
          <h2>通用设置</h2>
          <p>管理您的应用偏好和通用配置</p>
        </div>
        
        <div class="form-section">
          <h3>界面设置</h3>
          <div class="form-group">
            <label>主题模式</label>
            <div class="radio-group">
              <label class="radio-item">
                <input type="radio" v-model="settings.theme" value="light" />
                <span>浅色模式</span>
              </label>
              <label class="radio-item">
                <input type="radio" v-model="settings.theme" value="dark" />
                <span>深色模式</span>
              </label>
              <label class="radio-item">
                <input type="radio" v-model="settings.theme" value="auto" />
                <span>跟随系统</span>
              </label>
            </div>
          </div>
          
          <div class="form-group">
            <label>语言设置</label>
            <select v-model="settings.language">
              <option value="zh-CN">简体中文</option>
              <option value="zh-TW">繁体中文</option>
              <option value="en-US">English</option>
            </select>
          </div>
        </div>
        
        <div class="form-section">
          <h3>内容设置</h3>
          <div class="form-group">
            <label class="checkbox-item">
              <input type="checkbox" v-model="settings.showImages" />
              <span>自动加载图片</span>
            </label>
          </div>
          
          <div class="form-group">
            <label class="checkbox-item">
              <input type="checkbox" v-model="settings.autoPlay" />
              <span>自动播放视频</span>
            </label>
          </div>
          
          <div class="form-group">
            <label>每页显示文章数</label>
            <select v-model="settings.pageSize">
              <option value="10">10篇</option>
              <option value="20">20篇</option>
              <option value="50">50篇</option>
            </select>
          </div>
        </div>
        
        <div class="form-section">
          <h3>隐私设置</h3>
          <div class="form-group">
            <label class="checkbox-item">
              <input type="checkbox" v-model="settings.allowAnalytics" />
              <span>允许数据分析</span>
            </label>
          </div>
          
          <div class="form-group">
            <label class="checkbox-item">
              <input type="checkbox" v-model="settings.allowCookies" />
              <span>允许Cookie</span>
            </label>
          </div>
        </div>
        
        <div class="form-actions">
          <button class="btn-primary" @click="saveSettings">保存设置</button>
          <button class="btn-secondary" @click="resetSettings">恢复默认</button>
        </div>
      </main>
    </div>
  </div>
</template>

<script>
import HeaderComponent from '@/components/HeaderComponent.vue';

export default {
  components: {
    HeaderComponent
  },
  name: 'GeneralSettings',
  props: {
    isLoggedIn: {
      type: Boolean,
      default: false
    },
    userInfo: {
      type: Object,
      default: () => ({})
    },
    showUserPanel: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      settings: {
        theme: 'light',
        language: 'zh-CN',
        showImages: true,
        autoPlay: false,
        pageSize: '20',
        allowAnalytics: true,
        allowCookies: true
      },
      originalSettings: {}
    }
  },
  mounted() {
    this.loadSettings();
  },
  methods: {
    loadSettings() {
      // 模拟加载设置
      this.originalSettings = { ...this.settings };
    },
    saveSettings() {
      // 保存设置
      console.log('保存设置:', this.settings);
      this.$message?.success('设置保存成功');
      this.originalSettings = { ...this.settings };
    },
    resetSettings() {
      // 重置设置
      this.settings = {
        theme: 'light',
        language: 'zh-CN',
        showImages: true,
        autoPlay: false,
        pageSize: '20',
        allowAnalytics: true,
        allowCookies: true
      };
    }
  }
}
</script>

<style scoped>
.general-settings {
  min-height: 100vh;
  background-color: #f5f5f5;
}

.main-layout {
  display: flex;
  max-width: 1200px;
  margin: 0 auto;
  background-color: white;
  min-height: calc(100vh - 60px);
}

.settings-sidebar {
  width: 250px;
  background-color: #fff;
  border-right: 1px solid #e5e5e5;
  padding: 20px 0;
}

.sidebar-header {
  padding: 0 20px 20px;
  border-bottom: 1px solid #e5e5e5;
}

.sidebar-header h3 {
  margin: 0;
  font-size: 18px;
  color: #333;
}

.settings-nav {
  list-style: none;
  padding: 0;
  margin: 0;
}

.nav-item {
  margin: 0;
}

.nav-link {
  display: flex;
  align-items: center;
  padding: 12px 20px;
  text-decoration: none;
  color: #666;
  transition: all 0.3s;
}

.nav-link:hover {
  background-color: #f8f9fa;
  color: #007bff;
}

.nav-item.active .nav-link {
  background-color: #e3f2fd;
  color: #007bff;
  border-right: 3px solid #007bff;
}

.nav-icon {
  margin-right: 10px;
  font-size: 16px;
}

.settings-content {
  flex: 1;
  padding: 20px;
  max-width: 800px;
}

.settings-header {
  margin-bottom: 30px;
}

.settings-header h2 {
  margin: 0 0 8px 0;
  font-size: 24px;
  color: #333;
}

.settings-header p {
  margin: 0;
  color: #666;
  font-size: 14px;
}

.form-section {
  background: white;
  border: 1px solid #e5e5e5;
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 20px;
}

.form-section h3 {
  margin: 0 0 20px 0;
  font-size: 18px;
  color: #333;
  border-bottom: 1px solid #e5e5e5;
  padding-bottom: 10px;
}

.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  margin-bottom: 8px;
  font-weight: 500;
  color: #333;
}

.form-group select {
  width: 100%;
  padding: 10px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 14px;
}

.radio-group {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
}

.radio-item {
  display: flex;
  align-items: center;
  cursor: pointer;
  font-weight: normal;
}

.radio-item input[type="radio"] {
  margin-right: 8px;
}

.checkbox-item {
  display: flex;
  align-items: center;
  cursor: pointer;
  font-weight: normal;
}

.checkbox-item input[type="checkbox"] {
  margin-right: 8px;
}

.form-actions {
  display: flex;
  gap: 12px;
  padding-top: 20px;
  border-top: 1px solid #e5e5e5;
}

.btn-primary,
.btn-secondary {
  padding: 10px 20px;
  border: none;
  border-radius: 4px;
  font-size: 14px;
  cursor: pointer;
  transition: background-color 0.3s;
}

.btn-primary {
  background-color: #007bff;
  color: white;
}

.btn-primary:hover {
  background-color: #0056b3;
}

.btn-secondary {
  background-color: #6c757d;
  color: white;
}

.btn-secondary:hover {
  background-color: #545b62;
}
</style>